var a = document.documentElement.clientHeight - 110;
		var b = document.documentElement.clientWidth - 20;
		//选题ID
		var managerid;
		//DS ID
		var datastoreId = 'bj_xt';
		//字段缓存
		var clons = {};
		//对照信息
		//xtType 选题类型     author 作者  station 站点 oparator 用户
		//本页的选题立项数据
		var xtpldata = new Array();
		//选中的暂存对象
		var rowObj = {};
		
		var flowNodeArr;
		var execState;
		var xtArr;
		var bumenArr;
		
		$(function(){
			a = document.documentElement.clientHeight - 110;
		 	b = document.documentElement.clientWidth - 20;
			
			//窗口初始化
			$('#parentTabPanel').window('setTitle',"选题计划");
			
			//加载按钮
			loadButns();
			//初始化datagrid
			loadDategrid();
			//加载字段
			loadClns();
			//加载对照信息
			loadDzSource();
		});
		
		//加载节点的对照信息
		function loadDzSource(){
			$.ajax({
				url:'../../dz/queryDzList',
				type:'post',
				data:{dzIds:'flow_nodes;exec_state;dz_xt;dz_operators;dz_bumen'},
				success:function(data){
					//xtType 选题类型     author 作者  station 站点 oparator 用户
					flowNodeArr = data[0];
					execState = data[1];
					xtArr = data[2];
					operators = data[3];
					bumenArr = data[4];
				}
			});
		}
		
		function flowBumenFormatter(value){
			for(var i=0; i<bumenArr.length; i++){
				if (bumenArr[i].ID == value) return bumenArr[i].NAME;
			}
			return value;
		}
		
		function flowNodeFormatter(value){
			for(var i=0; i<flowNodeArr.length; i++){
				if (flowNodeArr[i].ID == value) return flowNodeArr[i].NAME;
			}
			return value;
		}
		
		function flowOperatorsFormatter(value){
			for(var i=0; i<operators.length; i++){
				if (operators[i].ID == value) return operators[i].NAME;
			}
			return value;
		}
		
		function stateFormatter(value){
			if(value=='')return '未执行';
			for(var i=0; i<execState.length; i++){
				if (execState[i].ID == value) return execState[i].NAME;
			}
			return value;
		}
		
		function flowXTFormatter(value){
			for(var i=0; i< xtArr.length; i++){
				if (xtArr[i].ID == value)
				return xtArr[i].NAME;
			}
			return value;
		}
		
		//加载选题计划字段
		function loadClns(){
			$.ajax({
					type:'post',
					url:'../../framework/columnList',
					data:{'colId':'XTPlan'},
					success:function(data){
						if(data ==""){
							alert("字段数据为空");
						}else{
							//请求一个组织列的方法
							clons = data;
							divName='QUERYCLN';//条件字段
							makeQueryColumns(clons,divName);
						}
					}
			});
		}
		
		// 加载按钮
		function loadButns(){
			$.ajax({
				type:'post',
				url:'../../framework/buttonsListC',
				data:{'butnId':"XTPlanDe;XTPlanEt"},
				success:function(data){
					if(data == ""){
						alert("按钮数据为空");
					}else{
						var buttons = data;
						var butHTML = "";
						for(var i = 0; i < buttons.length; i++){
							butHTML += formatButtons(buttons[i]);
						}
						$('#BUTTONS').html(butHTML);
						$('#QUERYBUT').html(butHTML);
						$.parser.parse();  //重新编译界面
					}
				}
			});
		}
		
		// 加载数据表格
		function loadDategrid(){
			$.ajax({
				type:'post',
				url:'../../framework/listQueryJson',
				data:{'dsId':'XTPlan','colId':'XTPlan','execFlag':''},
				success:function(data){
					if(data==""){
						alert("数据为空");
					}else{
						//给datagrid赋列值，没有数据
						mdatagrid(data);
					}
				}
			});
		}
		
		// 初始化Datagrid
		function mdatagrid(data){ //传入的是queryJson 里面就有columns和rows
			var lastIndex;
			$('#DATALIST').datagrid({
				iconCls:'icon-save',
				height:a,
				width:b,
				striped: true,				 
				collapsible:true,
				autoRowHeight: false,		
				sortOrder: 'desc',
				remoteSort: false,
				pageList:[30,50,100,150],
				columns:[[]],
				pagination:true,
				rownumbers:true,
				singleSelect:true,
				onDblClickRow:function(rowIndex,rowData){
					showInfoWin(rowData.MANAGE_ID);
				}
			});
			var dataGrid = $('#DATALIST');
			dataGrid.datagrid(jointColumn(data.columns));//根据配置选项，生成datagrid  
		}
		
		//查询选题计划
		function queryXTPL(config){
			var configStr = parseConfig('QUERYCLN');
			$('#queryConfig').html(parseConfigStr('QUERYCLN'));
			$('#xtTabPanel').tabs('select','选题计划');
			//加载shuju
			$.ajax({
				url:'../../framework/loadData',
				data:{dsId:"XTPlan",config:configStr},
				success:function(queryJson){
					$('#DATALIST').datagrid("loadData", queryJson);
					xtpldata = queryJson.rows;
					$('#DATALIST').datagrid({url:queryJson.url});
				}
			});
		}
		
		// 显示选题计划详情界面  1.加载字段 2.填充记录   3.将字段变灰
		function showInfoWin(rowId){
			managerid = rowId;
			var contentHTML = "<div style='padding:20px;'><div id='INFOPAGEBUT'></div><form id='upXTPLWin'><table id='upXTWin'></table></form></div>";
			divName='upXTPLWin';//条件字段
			var tmpC = 0;
			var okj = {};
						for(var i = 0; (i < xtpldata.length) && (tmpC ==0); i ++){
							if( xtpldata[i].MANAGE_ID == managerid){
								okj = xtpldata[i];
								rowObj = xtpldata[i];
								tmpC = 1;
							}
						}
			if(addYWTab('xtTabPanel',"选题计划详情",contentHTML)!=1){
				//加载字段\按钮
				makeColumns(clons,divName);
				//因为上述没有ajax 请求，所以可以直接找到每个录入框
				//动态加载对照值   动态填充   全部变灰 //为确保动态对照加载完毕，所以ajax请求不可用封装的方法
				var dzIdstr = serializeEDIType(divName);
				$.ajax({
					url:'../../dz/queryDzList',
					type:'post',
					data:{dzIds:dzIdstr},
					success:function(data){
							//下拉框
							fillSelect(divName,data);
							fillInfo(divName,okj);
							//将字段变灰
							readOnlyAll(divName);
					}
				});
				//加载多种按钮
				$.ajax({
					type:'post',
					url:'../../framework/buttonsListC',
					data:{'butnId':'XTPLInfo'},
					success:function(data){
						if(data == ""){
							alert("按钮数据为空");
						}else{
							var buttons = data;
							var butHTML = "";
							for(var i = 0; i < buttons.length; i++){
								butHTML += formatButtons(buttons[i]);
							}
							$('#INFOPAGEBUT').html(butHTML);
							$.parser.parse('#INFOPAGEBUT');  //重新编译按钮
						}
					}
				});
				//加载对照信息
			}else{
				fillInfo(divName,okj);
				//将字段变灰
				readOnlyAll(divName);
			}
		}
		
		//显示修改环节点页面   1.加载字段  2.填充
		function showPlanInfo(){
			divName='upTopicPlanTb';//条件字段
			if(addYWTab('xtTabPanel',"修改选题计划环节","<div style='padding:20px;'><div id='UPTOPICBUT'></div><form id='upTopicForm'><table id='upTopicPlanTb'></table></form></div>")!=1){
				//加载字段\按钮
				makeColumns(clons,divName);
				$.ajax({
					type:'post',
					url:'../../framework/buttonsListC',
					data:{'butnId':'XTPLupSave;XTPlanEt'}, //XTupSave;XTsaveS 
					success:function(data){
						if(data == ""){
							alert("按钮数据为空");
						}else{
							var buttons = data;
							var butHTML = "";
							for(var i = 0; i < buttons.length; i++){
								butHTML += formatButtons(buttons[i]);
							}
							$('#UPTOPICBUT').html(butHTML);
							$.parser.parse('#UPTOPICBUT');  //重新编译界面
						}
					}
				});
				//加载对照信息
				var dzIdstr = serializeEDIType("upTopicPlanTb");
				$.ajax({
					url:'../../dz/queryDzList',
					type:'post',
					data:{dzIds:dzIdstr},
					success:function(data){
							//下拉框
							fillSelect(divName,data);
							fillInfo(divName,rowObj);
							//将部分字段变灰
							readOnlyPart(divName);
					}
				});
			}else{
				//填充记录
				fillInfo(divName,rowObj);
				readOnlyPart(divName);
			}
		}
		
 		//保存选题计划
		function updateXTPL(){
			$.ajax({
				type:'post',
				url:'../../node/updateFlowManager',
				data:$('#upTopicForm').serialize(),
				success:function(data){
					if(data.msg == "upsuccess"){
						$.messager.alert("提示","更新成功");
					}else if(data.msg == "fail"){
					 	$.messager.alert("提示","保存失败！","info");
					}else{
						$.messager.alert("提示",data.msg,"error");
					}
				}
			});
		}
		
		//编辑选题计划
		var formaWinFlag = 'F';
 		function editPlan(){
 			var row = $('#DATALIST').datagrid('getSelected');
 			var selXTid = '';
 			if(row != null) selXTid = row.XT_ID;
 			divName='upTopicPlanTb';//条件字段
			if(addYWTab('xtTabPanel',"编辑选题计划","<div><div id='EtPlanDataGrid'></div></div>")!=1){
				//将EtPlanDataGrid 加载  页面   /node/editFlowManager
				if($('#EtPlanDataGrid').html()==''){
					$('#EtPlanDataGrid').load(
						'../../node/editFlowManager',
						{xtId:selXTid,formaWin:formaWinFlag},
						function(){
							formaWinFlag = 'T';
						});
				}
			}else{
				
			}
 		} 
 		
		function showQuery(){
			$('#xtTabPanel').tabs('select',"条件查询");
			$('#queryCB').removeAttr('checked');
		}
		